﻿
using System;
using System.Collections.Generic;
namespace Codemonk.Common.Caching
{
    /// <summary>
    /// 缓存集合接口
    /// </summary>
    /// <typeparam name="TKey">集合的键值类型</typeparam>
    /// <typeparam name="TValue">集合的缓存值类型</typeparam>
    public interface ICacheCollection<TKey, TValue> : IEnumerable<Tuple<TKey, TValue>>
    {
        /// <summary>
        /// 清空这个缓存
        /// </summary>
        void Clear();
        /// <summary>
        /// 获取缓存中的全部Key值
        /// </summary>
        System.Collections.Generic.IEnumerable<TKey> Keys { get; }
        /// <summary>
        /// 当前缓存数
        /// </summary>
        int Count { get; }
        /// <summary>
        /// 缓存是否包含这个键值
        /// </summary>
        /// <param name="key">键值</param>
        /// <returns>是否包含</returns>
        bool ContainsKey(TKey key);
        /// <summary>
        /// 添加或修改缓存到集合中
        /// </summary>
        /// <param name="key">键值</param>
        /// <param name="value">缓存值</param>
        void Set(TKey key, TValue value);
        /// <summary>
        /// 利用另一个缓存设置本缓存
        /// </summary>
        /// <param name="cache">另一个缓存</param>
        void Set(ICacheCollection<TKey, TValue> cache);
        /// <summary>
        /// 获取集合中缓存值
        /// </summary>
        /// <param name="key">键值</param>
        /// <param name="value">要返回的缓存值</param>
        /// <returns>是否查找到了缓存</returns>
        bool TryGet(TKey key, out TValue value);
    }
}
